package cn.iocoder.yudao.framework.datasource.local;

import java.util.Map;

/**
 * TODO
 *
 * @className: TenantLocalContext
 * @author: tangkh
 * @date: 2023-09-19 17:29
 */
public class TenantLocalContext {
    private static final String LOCAL_TENANT_ID = "LOCAL_TENANT_ID";

    public TenantLocalContext() {
    }

    public static void setTenantId(Long tenantId) {
        ThreadLocalContext.setAttachment("LOCAL_TENANT_ID", tenantId);
    }

    public static Long getTenantId() {
        ThreadLocalModel threadLocalModel = ThreadLocalContext.getLocalContext();
        Map<String, Object> attachments = threadLocalModel.getAttachments();
        Object tenantId = attachments.get("LOCAL_TENANT_ID");
        return Long.valueOf(tenantId.toString());
    }

    public static void clearTenantId() {
        ThreadLocalContext.removeLocalContext();
    }
}